package TrackModel;

/**
 * @author Jordan
 *Sub-Class of Block that adds additional functionality for a Switch Block
 */
public class SwitchBlock extends Block 
{
	private boolean switchState;
	
	/**Constructor for a Switch Block object. Initializes the switch to "true" meaning it goes to the block with the sequential block ID
	 * @param theBlock - The String array containing the attributes that need to be set for this Block
	 */
	public SwitchBlock(String[] theBlock)
	{
		super(theBlock);
		switchState = true;
	}
	
	/**
	 * @return Returns the new state of the switch after it has been toggled
	 */
	public boolean toggleSwitch()
	{
		switchState = !switchState;
		return switchState;
	}
	
	/* (non-Javadoc)
	 * @see TrackModel.Block#toString()
	 * Returns a String representation of this Switch Block object
	 */
	public String toString()
	{
		StringBuilder other = new StringBuilder();
		if (isUnderground)
			other.append("Underground ");
		other.append("Switch state = ");
		if (switchState)
			other.append("1\n");
		else
			other.append("0\n");
		if (connections.length == 1)
			return "Block ID: "+blockID+"\tLength: "+length+"\tGrade: "+grade+"\tSpeed Limit: "+speedLimit+"\nElevation: "+elevation+"\t"
					+ "Connected to Block: "+connections[0]+"\nOther information: "+other.toString();
		else
			return "Block ID: "+blockID+"\tLength: "+length+"\tGrade: "+grade+"\tSpeed Limit: "+speedLimit+"\nElevation: "+elevation+"\t"
					+ "Connected to Blocks: "+connections[0]+", "+connections[1]+"\nOther information: "+other.toString();
	}

	/**
	 * @return Returns the current state of the switch
	 */
	public boolean getSwitchState() 
	{
		return switchState;
	}
}
